/**
* Class Name: ifulfillSubmitToSalesRepControllerTest
* Author: Accenture
* Date: 07-Nov-2011
* Requirement/Project Name: iFulfill
* Requirement/Project Description: Test class for IfulfillMyTeamSearchCntrl
**/

@isTest

Private class ifulfillSubmitToSalesRepControllerTest{

    static testMethod void test_submitToSalesRepController(){
        
            Profile p = [select id from profile where name='System Administrator'];                     
            User u = new User(alias = 'ipsyas', email='isadmin@accenture.com',emailencodingkey='UTF-8', lastname='TestUser',languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='ifulfilladmin@testorg.com');  
            Insert u;        
            
            Profile profileTeleSales = [select id from profile where name='IOG Telesales'];                     
            User userTeleSales = new User(alias = 'iptele', email='istele@accenture.com',emailencodingkey='UTF-8', lastname='TeleSales User',languagelocalekey='en_US',localesidkey='en_US', profileid = profileTeleSales.Id,timezonesidkey='Asia/Calcutta', username='ifulfilltelesales@testorg.com');  
            
                
            Id OORSalesRepRecordType = Schema.SObjectType.Queries__c.getRecordTypeInfosByName().get('OOR Sales Rep').getRecordTypeId();    
            Id OORQueryRecordType= Schema.SObjectType.Queries__c.getRecordTypeInfosByName().get('OOR Query').getRecordTypeId();    


               Fullfilment_Item__c FI = new Fullfilment_Item__c(   Main_Listing_Phone_Number__c = '100',Listed_Name__c ='XYZ',Heading_Name__c ='Heading name',Item_Id__c = 'Item id' ,Product_Code__c ='p1',UDAC__c ='Udac1',Region__c = 'region1',Transaction_Type__c ='New',Sales_Rep__c= u.id);
              insert FI;
              Fullfilment_Item__c  tempFI = [select ownerID  from Fullfilment_Item__c  where id = :FI.id ];
              tempFI.ownerID = u.id;
              update tempFI;
      
      Query_Request__c qr = new Query_Request__c();
      qr.Fulfillment_Item__c = FI.id;
      qr.Request_Reason__c= 'Reason 1';
      insert qr;
      
         Query_Request__c tempQr = [select id from   Query_Request__c where id = :qr.id];
      
     system.runAs(userTeleSales ){
            Queries__c qry = new Queries__c(); 
            qry.Query_Request_ID__c =  tempQr.id;
            qry.Time_Queried__c=12;
            qry.Override_Sales_Rep__c = true;
            qry.RecordTypeID=OORSalesRepRecordType;
            qry.Sales_Rep_Name1__c=u.id;
            qry.Sales_Rep_Email__c='abc@test.com';
            qry.Sales_Mgr_Email1__c='xyz@test.com';
            qry.Last_Queried_on__c = system.Now();
            qry.Submitted_to_Sales_Rep__c ='xyz123';
            insert qry;
            
            PageReference pageRef = Page.iFulfillSubmitQueryResp;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController ctrl = new ApexPages.StandardController(qry);
            ifulfillSubmitToSalesRepController controller = new ifulfillSubmitToSalesRepController(ctrl);    
            try{
            controller.SubmitToSalesRep();}
            catch (Exception e)     {}            
           
              
             Queries__c qry2 = new Queries__c(); 
            qry2.Query_Request_ID__c =  tempQr.id;
            qry2.Time_Queried__c=12;
            qry2.Override_Sales_Rep__c = false;
            qry2.RecordTypeID=OORSalesRepRecordType;
            //qry2.Sales_Rep_Name__c=u.id;
            //qry2.Sales_Rep_Email__c='abc@test.com';
            //qry2.Sales_Mgr_Email__c='xyz@test.com';
            qry2.Last_Queried_on__c = system.Now();
            qry2.Submitted_to_Sales_Rep__c ='xyz123';
            insert qry2;
            
            
                        
            
            
            PageReference pageRef1 = Page.iFulfillSubmitQueryResp;
            Test.setCurrentPage(pageRef1);
            ApexPages.StandardController ctrl1 = new ApexPages.StandardController(qry2);
            ifulfillSubmitToSalesRepController controller1 = new ifulfillSubmitToSalesRepController(ctrl1);    
            try{
            controller1.SubmitToSalesRep();}
            catch (Exception e)     {}   
            
            Queries__c qry1 = new Queries__c(RecordTypeID=OORQueryRecordType,Time_Queried__c=12);
             qry1.Query_Request_ID__c =  tempQr.id;

            insert qry1;
            controller.SubmitQueryResp();
          }  
     }
 }